﻿@{
    ViewData["Title"] = "添加用户";
    Layout = "~/Areas/Manager/Views/Shared/_Layout.cshtml";
}
@section scriptstop
 {
<link href="~/layuiadmin/formSelects-v4.css" rel="stylesheet" />
 }
<div class="layui-bgn" style="padding-bottom:20px;">
    <form class="layui-form" style="padding: 20px 30px 0 0;" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">请选择角色</label>
            <div class="layui-input-block">
                <select xm-select="RoleIds" asp-items="@ViewBag.RolesList" lay-verify="select14"></select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="UserName" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" name="Password" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input type="password" name="ConfirmPwd" class="layui-input" lay-verify="confirpwd">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">真实姓名</label>
            <div class="layui-input-block">
                <input type="text" name="TrueName" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">昵称</label>
            <div class="layui-input-block">
                <input type="text" name="NickName" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电话</label>
            <div class="layui-input-block">
                <input type="text" name="Phone" class="layui-input" lay-verify="phone">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="Email" class="layui-input" lay-verify="email">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block">
                <input type="checkbox" name="Activity" value="true" checked lay-verify="activity" lay-skin="switch" lay-filter="switchTest">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add" id="submit" type="button">提交</button>
                <button id="close" type="button" class="layui-btn layui-btn-primary">关闭</button>
            </div>
        </div>
    </form>
</div>
    @section scriptsfeet
        {
        <script type="text/javascript">
            layui.config({
                base: '/layuiadmin/'
            }).extend({
                formSelects: 'formSelects-v4'
            }).use(['form', 'formSelects', 'sykjwh'], function () {
                var $ = layui.$,
                    form = layui.form,
                    formSelects = layui.formSelects,
                    sykjwh = layui.sykjwh;

                $("#close").click(function () {
                    sykjwh.close();
                });

                ////表单验证
                //form.verify({
                //    select14: function (value) {
                //        var count = value ? value.split(",").length : 0;
                //        if (count < 1) {
                //            return '请选择角色';
                //        }
                //    },
                //    confirpwd: function (value) {
                //        if (value === "")
                //            return "请确认密码！";
                //        var pwd = $('input[name=Password').val();
                //        if (pwd !== value)
                //            return "二次输入的密码不一致！";
                //    }
                //});

                //表单提交
                form.on('submit(add)', function (obj) {
                    //以数组获取所选角色ID集合
                    obj.field.RoleIds = formSelects.value('RoleIds', 'val');
                    sykjwh.save('@Url.Action("add", "users", new { area = Constant.AREAMANAGER })', obj.field);
                });
            });

        </script>
    }
